﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AiXiu.WebStite
{
    /// <summary>
    /// DiscussPublishHandler 的摘要说明
    /// </summary>
    public class DiscussPublishHandler : IHttpHandler
    {
        /// <summary>
        /// 接受用户请求 添加评论
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            //接受参数
            string videoId = context.Request.QueryString["id"];
            string nickName = context.Request.Form["nickName"];
            string avatar = context.Request.Form["avatar"];
            string content = context.Request.Form["content"];
            string replayTo = context.Request.Form["replayTo"];
            string addTime = context.Request.Form["addTime"];
            DateTime addTimeValues = TimeHelper.GetTimeByUnix(long.Parse(addTime));
            //添加或回复评论
            IDiscussManager discussManager = new DiscussManager();
            Model.Redis.Discuss discuss = new Model.Redis.Discuss()
            {
                NickName = nickName,
                Avatar = avatar,
                AddTime = addTimeValues,
                ReplayTo = replayTo,
                Content = content
            };
            discussManager.Add(videoId, discuss);
            //返回结果
            context.Response.ContentType = "text/plain";
            context.Response.Write("OK");
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}